// pages/my/my.js
import {
  imageUrl
} from "../../utils/imageutil"
import {
  is_auth
} from "../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageUrl,
    num: getApp().globalData.unreadCount,
    orderlist: [{
      title: '待付款',
      pic: '/my/obligation.png',
      icon: 'https://cyxf.xfyh4k5.com/jiazheng/image/my/Slice921.png',
      url: '../order/order?navcurr=1'
    }, {
      title: '待接单',
      pic: '/my/order_receiving.png',
      icon: 'https://cyxf.xfyh4k5.com/jiazheng/image/my/Slice922.png',
      url: '../order/order?navcurr=2'
    }, {
      title: '待服务',
      pic: '/my/service.png',
      icon: 'https://cyxf.xfyh4k5.com/jiazheng/image/my/Slice923.png',
      url: '../order/order?navcurr=3'
    }, {
      title: '待评价',
      pic: '/my/evaluate.png',
      icon: 'https://cyxf.xfyh4k5.com/jiazheng/image/my/Slice924.png',
      url: '../order/order?navcurr=4'
    }, {
      title: '已完成',
      pic: '/my/accomplish.png',
      icon: 'https://cyxf.xfyh4k5.com/jiazheng/image/my/Slice925.png',
      url: '../order/order?navcurr=5'
    }],
    setting: [{
        title: "实名认证",
        url: "./authentication",
        form_id:80000,
        id:3
      },
      {
        title: "地址管理",
        form_id:80000,
        url: "./address"
      },
      {
        title: "会员兑换",
        url: "./redeem_member",
        form_id:wx.getStorageSync('userInfo').form_id
      },
      {
        title: "意见反馈",
        form_id:80000,
        url: "./fk_list"
      },
      {
        title: "设置",
        form_id:80000,
        url: "./set",
        id:4
      },
    ],
    userInfo: wx.getStorageSync('userInfo'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let val = 'setting[2].form_id'
   this.setData({
     [val]:wx.getStorageSync('userInfo').form_id
   })
  },
  bindGetUserInfo: function (e) {
    if (!this.data.userInfo.img || this.data.userInfo.name == "微信用户") {
      this.getUserProfile()
      return
    }
    this.getUserProfile('has_img')


  },
  getUserProfile(has_img = "") {
    wx.navigateTo({
      url: '/pages/index/get_wx_info?has_img=' + has_img
    })
  },
  to_url(e) {
    if (!is_auth(true)) {
      return
    }
    let url = e.currentTarget.dataset.url;
    if (!is_auth(true)) {
      return
    }
    let id = e.currentTarget.dataset.id
    if (id == 3 && (this.data.userInfo.phonenumber == '' || this.data.userInfo.phonenumber == 0)) {
      if (!is_auth(true)) {
        return
      }
    } else if (id == 3 && (this.data.userInfo.id_number != '' || this.data.userInfo.id_number != 0)) {
      wx.showToast({
        title: '您已实名认证',
        icon: 'none'
      })
      return
    }

    if (url) {
      wx.navigateTo({
        url: e.currentTarget.dataset.url,
      })
    }
  },
  onConversationListUpdated() {
    this.setData({
      num: getApp().globalData.unreadCount
    })
  },
  onShow() {
    this.setData({
      userInfo: wx.getStorageSync('userInfo'),
      num: getApp().globalData.unreadCount
    })
  },
})